
using System.Data;
using MySqlConnector;

namespace Front._1127;

public partial class BookForm : Form
{
    public BookForm()
    {
        InitializeComponent();
    }

    private void BookForm_Load(object sender, EventArgs e)
    {
        //查询图书信息
        GetAllBooks();
        //查询图书分类信息
        GetAllBookCategories();
    }

    private void GetAllBookCategories()
    {
        
    }

    private void GetAllBooks()
    {
        using var connection = new MySqlConnection("server=localhost;port=3306;user=root;password=aaa20179725");
        connection.Open();
        
        //sql
        string sql = "SELECT  * FROM book_info;";
        //创建适配器对象
        MySqlDataAdapter adapter = new MySqlDataAdapter(sql, connection);
        //创建数据集
        DataSet dataSet = new DataSet();
        //填充数据
        adapter.Fill(dataSet, "book_category");
        
        //插入全部行
                DataTable dataTable = dataSet.Tables["book_category"];
                DataRow row = dataTable.NewRow();
                row[0] = "全部";
                dataTable.Rows.InsertAt(row,0);
        
        //绑定数据
        this.comboBox1.DataSource =dataTable;
        this.comboBox1.DisplayMember = DataTable.Columns[0].ColumnName;
        
        
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
    }

    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        throw new System.NotImplementedException();
    }
}

internal class Dataset : DataSet
{
}
